const { get, xin, getOne, addImgs, xiu, shan, cha, deleteimg } = require("../api/cinemas.js")
var express = require('express');
const { json } = require("express");

var router = express.Router();
/* GET home page. */

/**,
 * @swagger
 * /cinemas:
 *    get:
 *      tags:
 *      - 影院列表管理模块          # 接口分类
 *      summary: 获取影院信息   # 接口备注
 *      description: 获取影院信息   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      parameters:
 *        - in: query
 *          name: curPage
 *          schema:
 *            type: integer
 *            default: 1
 *          required: true
 *          description: 当前页码
 *        - in: query
 *          name: eachPage
 *          schema:
 *            type: integer
 *            default: 10
 *          required: true
 *          description: 每页显示条数
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "获取成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/cinemas'
 *
 * */
router.get('/', async function (req, res, next) {
  const { curpage, eachPage } = req.query
  const data = await get({ curpage, eachPage })
  res.send(data);
});

/**,
 * @swagger
 * /cinemas:
 *    post:
 *      tags:
 *      - 影院列表管理模块          # 接口分类
 *      summary: 新增影院信息   # 接口备注
 *      description: 用于新增影院的基本信息   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/cinemas'
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "新增成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/cinemas'
 *
 * */
router.post('/', async function (req, res, next) {
  const cinemas = req.body
  const data = await xin(cinemas);
  console.log(data);
  res.send(data);
});
/**,
 * @swagger
 * /cinemas/{_id}:
 *    get/:_id:
 *      tags:
 *      - 影院列表管理模块          # 接口分类
 *      summary: 获取某个影院信息   # 接口备注
 *      description: 通过_id获取某个影院信息   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *     parameters:
 *        - in: path
 *          name: _id
 *          schema:
 *            type: string
 *            default: 604adf53400f8b8f31160ee4
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "获取成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/cinemas'
 *
 * */
router.get('/:_id', async function (req, res, next) {
  JSON.parse
  const { _id } = req.params;
  const data = await getOne(_id);
  res.send(data);
});
/**,
 * @swagger
 * /cinemas/:_id/imgs/:url:
 *    patch:
 *      tags:
 *      - 影院列表管理模块          # 接口分类
 *      summary: 新增影院照片   # 接口备注
 *      description: 新增影院照片   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/cinemas'
 *            example:"
 *              _id: "60ddae2613abde4cf4a6735f"  
 *              name : "承光影界（航空港店）"
 *              address : "双流区临港路二段承光影城"
 *              phone : "0444-555-777"
 *              status : true  
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "获取成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/cinemas'
 *
 * */
router.patch('/:_id/imgs/:url', async function (req, res, next) {
  const { _id, url } = req.params;
  await addImgs({ _id, url });
  const data = await getOne(_id);
  res.send(data);
});
/**,
 * @swagger
 * /cinemas/xiu:
 *    patch:
 *      tags:
 *      - 影院列表管理模块          # 接口分类
 *      summary: 修改影院基本信息   # 接口备注
 *      description: 用于通过_id获取的影院信息来修改影院基本信息   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/cinemas'
 *            example:
 *              _id: "60ddae2613abde4cf4a6735f"  
 *              name : "承光影界（航空港店）"
 *              address : "双流区临港路二段承光影城"
 *              phone : "0444-555-777"
 *              status : true  
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "获取成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/cinemas'
 *
 * */
router.patch('/xiu', async function (req, res, next) {
  const cinema = req.body
  console.log('============', req.body);
  const data = await xiu(cinema);
  res.send(data);
});
/**,
 * @swagger
 * /cinemas/shan:
 *    delete:
 *      tags:
 *      - 影院列表管理模块          # 接口分类
 *      summary: 删除某个影院信息   # 接口备注
 *      description: 通过_id删除某个影院信息   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/cinemas'
 *            example:
 *               _id: "60d9dd0b3201fa4de4d1b342"
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "删除成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/cinemas'
 *
 * */
router.delete('/shan', async function (req, res, next) {
  const cinema = req.body
  console.log('============', req.body);
  const data = await shan(cinema);
  console.log(data);
  console.log(cinema);
  res.send(data);
});
/**,
 * @swagger
 * /cinemas/searchCinemas:
 *    post:
 *      tags:
 *      - 影院列表管理模块          # 接口分类
 *      summary: 通过查询条件查询影院信息   # 接口备注
 *      description: 用于通过查询条件查询影院信息   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/cinemas'
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "查询成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/cinemas'
 *
 * */
router.post('/searchCinemas', async function (req, res, next) {
  const cinema = req.body
  console.log('============', req.body);
  const data = await cha(cinema);
  console.log(data);
  res.send(data);
});
/**,
 * @swagger
 * /chinemas/:_id/imgs/:url:
 *    delete:
 *      tags:
 *      - 影院列表管理模块          # 接口分类
 *      summary: 删除某个影院的图片   # 接口备注
 *      description: 删除某个影院信息的图片   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/chinemas'
 *            example:
 *               _id: "60d9dd0b3201fa4de4d1b342"
 *               url: "/common/99227016f6c06.jpg"
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "删除成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/chinemas'
 *
 * */
router.delete('/:_id/imgs/:url', async function (req, res, next) {
  const { _id, url } = req.params;
  const result = await deleteimg({ _id, url });
  console.log(result);
  const data = await getOne(_id);
  res.send(data);
});


module.exports = router;
